package com.gxa.controller.discrepancy;

import com.gxa.common.utils.R;
import com.gxa.entity.discrepancy.Audit;
import com.gxa.entity.discrepancy.ComingVisitor;
import com.gxa.entity.discrepancy.Track;
import com.gxa.entity.discrepancy.search.AudiSearchMap;
import com.gxa.service.discrepancy.AuditService;
import com.gxa.service.discrepancy.ComingVisitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Api(tags = "访客管理--->访客审核")
@RestController
@RequestMapping("/audit")
public class AuditController {

    @Autowired
    private AuditService service;

    @Autowired
    private ComingVisitorService comingVisitorService;


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("访客审核列表接口")
    @GetMapping("/list")
    public R queryAll(AudiSearchMap map){
        List<ComingVisitor> comingVisitors = comingVisitorService.getBaseMapper().selectList(null);
        int orderCount = comingVisitorService.getOrderCount();
        int comingCount = comingVisitorService.getComingCount();
        int leavingCount = comingVisitorService.getLeavingCount();
        int uncomeCount = comingVisitorService.gerUncomeCount();
        return ok("successs").put("data",service.queryByPage(map)).put("coming-visitors",comingVisitors).put("orderCount",orderCount).put("comingCount",comingCount).put("leavingCount",leavingCount).put("uncomeCount",uncomeCount);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增访客审核接口")
    @PostMapping("/add")
    public R add(@RequestBody Audit device){
        if(service.save(device)){
            return ok("添加成功！");
        }
        return error("add fail");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除访客审核接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        if(service.removeById(id)){
            return ok("删除成功！");
        }

        return error("del error");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑访客审核接口")
    @PutMapping("/edit")
    public R edit(@RequestBody Audit device){
        if(service.updateById(device)){
            return ok("更新成功！");
        }
        return error("edit error");
    }
}
